﻿
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SmartMotion.Core;
using SmartMotion.Core.Mgrs;

namespace SmartMotion.Product
{
    public partial class frmParAdd : UIForm
    {
        public frmParAdd()
        {
            InitializeComponent();
            _result = new VarInfo();
        }

        private VarInfo _result;

        public VarInfo Result { get => _result;}

        private void uiSymbolButton1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            if (txtGroup.Text==string.Empty)
            {
                _result.Group = "Default";
            }
            Close();
        }

        private void txtGroup_TextChanged(object sender, EventArgs e)
        {
            _result.Group = txtGroup.Text;
        }

        private void txtName_TextChanged(object sender, EventArgs e)
        {
            _result.Name = txtName.Text;
        }
        

        private void typeString_Click(object sender, EventArgs e)
        {
        
            if (typeString.Checked)
            {
                string value = "请输入字符串类型的值";
                if (this.InputStringDialog(ref value, true, "请输入字符串类型的值：", true))
                {
                    _result.Value = value;
                    _result.Type = typeof(string).FullName;
                }
            }
            else if (typeInt.Checked)
            {
                int value = 0;
                if (this.InputIntegerDialog(ref value,desc:"请输入整数类型的值："))
                {
                    _result.Value = value;
                }

                if (this.InputIntegerDialog(ref value, desc: "请输入整数类型的下限值："))
                {
                    _result.Min = value;
                }

                if (this.InputIntegerDialog(ref value, desc: "请输入整数类型的上限值："))
                {
                    _result.Max = value;
                }
                _result.Type = typeof(int).FullName;
            }
            else if (typeUint.Checked)
            {
                int value = 0;
                if (this.InputIntegerDialog(ref value, desc: "请输入整数类型的值："))
                {
                    _result.Value =Convert.ToUInt32(value);
                }

                if (this.InputIntegerDialog(ref value, desc: "请输入整数类型的下限值："))
                {
                    _result.Min = Convert.ToUInt32(value);
                }

                if (this.InputIntegerDialog(ref value, desc: "请输入整数类型的上限值："))
                {
                    _result.Max = Convert.ToUInt32(value);
                }
                _result.Type = typeof(uint).FullName;
            }
            else if (typeShort.Checked)
            {
                int value = 0;
                if (this.InputIntegerDialog(ref value, desc: "请输入整数类型的值："))
                {
                    _result.Value = Convert.ToInt16(value) ;
                }

                if (this.InputIntegerDialog(ref value, desc: "请输入整数类型的下限值："))
                {
                    _result.Min = Convert.ToInt16(value);
                }

                if (this.InputIntegerDialog(ref value, desc: "请输入整数类型的上限值："))
                {
                    _result.Max = Convert.ToInt16(value);
                }
                _result.Type = typeof(short).FullName;
            }
            else if (typeUShort.Checked)
            {
                int value = 0;
                if (this.InputIntegerDialog(ref value, desc: "请输入整数类型的值："))
                {
                    _result.Value = Convert.ToUInt16(value) ;
                }

                if (this.InputIntegerDialog(ref value, desc: "请输入整数类型的下限值："))
                {
                    _result.Min = Convert.ToUInt16(value);
                }

                if (this.InputIntegerDialog(ref value, desc: "请输入整数类型的上限值："))
                {
                    _result.Max = Convert.ToUInt16(value);
                }
                _result.Type = typeof(ushort).FullName;
            }
            else if (typeDouble.Checked)
            {
                double value = 0;
                if (this.InputDoubleDialog(ref value,desc:"请输入Double类型的值"))
                {
                    _result.Value = value;
                }
                if (this.InputDoubleDialog(ref value, desc: "请输入Double类型的下限值"))
                {
                    _result.Min = value;
                }
                if (this.InputDoubleDialog(ref value, desc: "请输入Double类型的上限值"))
                {
                    _result.Max = value;
                }
                _result.Type = typeof(double).FullName;
            }
            else if (typeBool.Checked)
            {
                int selIndex = 0;
                List<bool> items = new List<bool>() {true, false};
                if (this.ShowSelectDialog(ref selIndex, items))
                {
                  _result.Value = items[selIndex];

                }
                _result.Type = typeof(bool).FullName;

            }
            try
            {
                txtValue.Text = _result.Value.ToString();
                txtMin.Text = _result.Min.ToString();
                txtMax.Text = _result.Max.ToString();
            }
            catch (Exception ex)
            {

                
            }
            
        }

        private void txtRemark_TextChanged(object sender, EventArgs e)
        {
            _result.Remark = txtRemark.Text;
        }
    }
}
